/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.webhomesites.configuracao.infra;


import br.com.webhomesites.configuracao.presenter.EmpresaPresenter;
import java.awt.Container;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 *
 * @author Webhome
 */
public class ContainerSpring {

    private ApplicationContext contextoSpring;

    private ApplicationContext getContextoSpring() {
        if (contextoSpring == null) {
            contextoSpring = new ClassPathXmlApplicationContext("applicationContext.xml");
        }
        return contextoSpring;
    }
    
    public Object getFactory(String bean) {
        BeanFactory factory = getContextoSpring();         
        return factory.getBean(bean);
    }

    public Object getBean(String nome) {
        ApplicationContext contexto = getContextoSpring();
        if (contexto != null) {
            try {
                return contexto.getBean(nome);
            } catch (NoSuchBeanDefinitionException ex) {
                return null;
            }
        }
        return null;
    }

    public static synchronized Container getInstancia() {
        return _instancia;
    }
    private static Container _instancia = new Container();

}
